package com.jeremyfeinstein.conference;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;

import com.intel.webrtc.base.Stream;
import com.jeremyfeinstein.OnCustomTouchListener;
import com.jeremyfeinstein.slidingmenu.lib.R;

/**
 * Created by sunxunchao on 2018/9/27.
 */
public class NewZoomDialogManger implements CustomDialog.CallBack{

    private static final String TAG = "NewZoomDialogManger";
    private Context context;
    private GLSurfaceView zoomSurfaceView;
    private CustomSurfaceRenderer zoomSurfaceRenderer;
    private Stream.VideoRendererInterface zoomStreamRenderer;
    private volatile boolean subscribeSuccess = false;//true 订阅视频成功 ， false 订阅视频失败


    private int ballspeed;

    private OnZoomListener onZoomListener;
    private static final int DEFAULT_SPEED = 60; //球机默认旋转速度
    private int preReceived;
    private int preRendered;
    private ProgressBar progress_video;

    public int getPreReceived() {
        return preReceived;
    }

    public NewZoomDialogManger(Context context, OnZoomListener onZoomListener) {
        this.context = context;
        this.onZoomListener = onZoomListener;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public void handleView(final Dialog dialog, View dialogView) {
        zoomSurfaceView = (GLSurfaceView) dialogView.findViewById(R.id.zoomView);
        zoomSurfaceRenderer = new CustomSurfaceRenderer(zoomSurfaceView);
        zoomStreamRenderer = zoomSurfaceRenderer.createVideoRenderer();


        if (onZoomListener != null) {
            onZoomListener.onStartSubscribe(zoomSurfaceRenderer, zoomStreamRenderer, this);
        }

        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {

                if (onZoomListener != null) {
                    onZoomListener.onDismiss(zoomSurfaceRenderer, zoomStreamRenderer);
                }
            }
        });

        zoomSurfaceView.setOnTouchListener(new OnCustomTouchListener() {
            @Override
            protected void onDoubleClicked(View view) {
                Log.d(TAG, "onDoubleClicked: ");
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }

            @Override
            protected void onClicked(View view) {
                Log.d(TAG, "onClicked: ");
            }

            @Override
            protected void onSlidUp(View view) {
            }

            @Override
            protected void onSlidDown(View view) {
            }
        });

    }





    public interface OnZoomListener {
        void onStartSubscribe(CustomSurfaceRenderer zoomSurfaceRenderer, Stream.VideoRendererInterface zoomStreamRenderer, NewZoomDialogManger manger);

        void onDismiss(CustomSurfaceRenderer zoomSurfaceRenderer, Stream.VideoRendererInterface zoomStreamRenderer);

    }

}
